package com.woniuxy.warehouse.controller;

import com.woniuxy.commons.entity.warehouse.IoWarehouse;
import com.woniuxy.commons.entity.warehouse.IoWarehouseProduct;
import com.woniuxy.commons.entity.warehouse.dto.SaleGoodInfoDto;
import com.woniuxy.commons.result.Result;
import com.woniuxy.warehouse.service.IoWarehouseProductService;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:SHEAndme
 * @Todo:TODO
 * @DateTime:2022/4/20 15:35
 * @Component:霍格沃兹魔法学院
 **/
@RestController
@RequestMapping("/warehouse/warehouseProduct")
public class IoWarehouseProductController {
    /**
     * 服务对象
     */
    @Resource
    private IoWarehouseProductService ioWarehouseProductService;


    @ApiOperation(value = "批量新增出入库物件信息")
    @PostMapping("/addIoWarehouseProducts")
     public  Result batchAdd(@RequestBody List<IoWarehouseProduct> ioWarehouseProducts) {
        return ioWarehouseProductService.insertBatch(ioWarehouseProducts);
    }


    /**
     * @return null
     * @description TODO 查询下半部分消息
     */
    @ApiOperation(value = "查找三表")
    @PostMapping("/findSaleGoodInfo/{pageNum}/{pageSize}")
    public  Result findSaleGoodInfo(
            @PathVariable("pageNum") Integer currentPage,
            @PathVariable("pageSize") Integer pageSize) {
        return ioWarehouseProductService.findSaleGoodInfo(currentPage,pageSize);
    }


    /**
     * 分页查询
     * @return 查询结果
     * TODO: 这个是分页查 产品信息
     */
    @ApiOperation(value = "这个是分页查 产品信息")
    @PostMapping("/findAll/{pageNum}/{pageSize}")
    public Result findAllProduct(@PathVariable("pageNum") Integer currentPage,
                                 @PathVariable("pageSize") Integer pageSize,
                                 @RequestBody IoWarehouseProduct ioWarehouseProduct) {
        return   ioWarehouseProductService.queryByPage(currentPage,pageSize,ioWarehouseProduct);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据 根据id单个查找
     */
    @PostMapping("/findBy/{id}")
    public Result queryById(@PathVariable("id") Integer id) {
        return ioWarehouseProductService.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param ioWarehouseProduct 实体
     * @return 新增结果  单条数据
     */
    @PostMapping("/add")
    public Result add(@RequestBody IoWarehouseProduct ioWarehouseProduct) {
        return ioWarehouseProductService.insert(ioWarehouseProduct);
    }

    /**
     * 编辑数据
     *
     * @param ioWarehouseProduct 实体
     * @return 编辑结果
     */
    @PutMapping("/update")
    public Result edit(@RequestBody IoWarehouseProduct ioWarehouseProduct) {
        return ioWarehouseProductService.update(ioWarehouseProduct);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable("id") Integer id) {
        return Result.ok(ioWarehouseProductService.deleteById(id));
    }

}
